﻿using System;

namespace NodeJS.stream
{
    [NonScript]
    public interface IWritable
    {
        /// <summary>
        /// This method writes some data to the underlying system, and calls the supplied callback once the data has been fully handled.
        /// The return value indicates if you should continue writing right now. If the data had to be buffered internally, then it will return false. Otherwise, it will return true.
        /// </summary>
        /// <param name="chunk"></param>
        /// <param name="encoding"></param>
        /// <param name="callback"></param>
        /// <returns>True if the data was handled completely.
        /// This return value is strictly advisory. You MAY continue to write, even if it returns false. However, writes will be buffered in memory, so it is best not to do this excessively. Instead, wait for the drain event before writing more data.
        /// </returns>
        bool Write(StringOrBuffer chunk, string encoding = "", Action callback = null);

        /// <summary>
        /// Call this method when no more data will be written to the stream.
        /// </summary>
        /// <param name="chunk"></param>
        /// <param name="encoding"></param>
        /// <param name="callback">Optional callback for when the stream is finished</param>
        /// <returns></returns>
        bool End(StringOrBuffer chunk = null, string encoding = "", Action callback = null);
    }
}
